set more off
global user `c(username)'
*** Set WD
global d0 /Users//$user/Dropbox/SurveyCovid19/
cd "$d0"


*** Directories
global data "Descriptive paper/Clean Data/"
global tables "Descriptive paper/Tables/"
global figures "Descriptive paper/Figures/figures inequality/"
global enddate"1may2020"
global clean "C:\Users\\$user\Dropbox\SurveyCovid19\Descriptive paper\Data for replication"

use "$clean\data_figure2.dta", clear

collapse perdioempleo cerronegocio lost_livelihood trabajocasa gdp_pc_ppp selfemployed informal ,by(country_cod)
replace perdioempleo=perdioempleo*100
replace cerronegocio=cerronegocio*100
replace lost_livelihood=lost_livelihood*100
format cerronegocio %9.0f
format perdioempleo %9.0f
format lost_livelihood %9.0f

replace trabajocasa=trabajocasa*100
gen pos=12
replace pos=1 if country_cod=="SLV"
gen pos2=6
replace pos2=3 if country_cod=="SUR"

*Graph 1: Job loss and Self-Employment
global details graphregion(color(white)) legend(off) xlabel(#10,labsize(small)) ylabel(#10,labsize(small))
global titles title(Loss of livelihood and self-employment)  ytitle(% of respondents) xtitle(Share of self-employed workers (WDI))
global options $titles $details
global g1 lost_livelihood selfemployed
global o1 mlabel(country_cod perdioempleo) mlabsize(vsmall) mlabposition(12)  mlabvposition(pos) mlabcolor(black) 
global o2 msym(i) mlabel(lost_livelihood) mlabposition(6) mlabsize(vsmall) mlabvposition(pos2)    

tw (scatter $g1, mcolor(maroon) $o1) (scatter $g1, $o2) (lfit $g1, lcolor(maroon)), $options     
graph export "$d0\$figures Figure2.pdf", replace as(pdf)
graph export "$d0\$figures Figure2.eps", replace as(eps)

